//
//  SuiJiViewModel.m
//  GuShiNews
//
//  Created by 丁一 on 2019/8/20.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "SuiJiViewModel.h"
#import "HJonesNetting.h"
#import "NewsModel.h"

@implementation SuiJiViewModel

- (instancetype)init:(id)responseObject{
    if (self = [super init]) {
        
        [HJonesNetting JonesNetting_POST:responseObject
                                  andURL:Side_SuiJi_News
                              andtimeout:20.0
                                finished:^(NSError * _Nonnull error, NSDictionary * _Nonnull resultDict) {
                                    if (error) {
                                        [SVProgressHUD showErrorWithStatus:@"网络加载失败"];
                                        [self.delegate SuijiSideNewsSucces:0 array:nil page:0];
                                    }else{
                                        if ([[resultDict objectForKey:@"Code"] longLongValue]==1000) {
                                            
                                            NSMutableArray *hudonglist = [NewsModel mj_objectArrayWithKeyValuesArray:[resultDict objectForKey:@"HomeNewsArray"]];
                                            
                                            [hudonglist enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                                                NewsModel *model = (NewsModel *)obj;
                                                
                                                model.title_height = [HuaHereClass size:model.news_tittle font:[UIFont boldSystemFontOfSize:23] width:RECRWITCH-50 height:1000].height+20;
                                                if ([model.news_img isEqualToString:@""]||model.news_img.length<10) {
                                                    model.news_show_type = 0;
                                                    model.news_height = 105 + 30;
                                                }else{
                                                    model.news_show_type = 1;
                                                    model.news_height = 120 + 20;
                                                }
                                                
                                                
                                                NSString *resultStr = [model.news_info stringByReplacingOccurrencesOfString:@"/n" withString:@"\n"];
                                                model.news_info = resultStr;
                                                
                                                
                                                model.info_height = [HuaHereClass size:model.news_info font:[UIFont systemFontOfSize:18] width:RECRWITCH-50 height:100000].height+35;
                                                
                                                NSString *temp = [model.news_info stringByReplacingOccurrencesOfString:@" " withString:@""];
                                                temp = [temp stringByReplacingOccurrencesOfString:@"\r" withString:@""];
                                                temp = [temp stringByReplacingOccurrencesOfString:@"\n" withString:@""];
                                                temp = [temp stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
                                                
                                                model.wen_string = temp;
                                                model.wen_count = temp.length;
                                                model.wen_time = model.wen_count/150;
                                                
                                            }];
                                            
                                            [self.delegate SuijiSideNewsSucces:1 array:hudonglist page:0];
                                        }else{
                                            [SVProgressHUD showErrorWithStatus:[resultDict objectForKey:@"Message"]];
                                            [self.delegate SuijiSideNewsSucces:0 array:nil page:0];
                                        }
                                    }
                                }
                              passmanger:^(NSURLSessionDataTask * _Nonnull manger) {
                                  
                              }
                             andprogress:^(NSProgress * _Nonnull CProgress) {
                                 
                             }];
        
    }
    return self;
}

@end
